<?php if (!defined('FIT_PATH')) exit('No direct script access allowed');
/**
 * @copyright 2009 - 2011 Bincent.com. All Rights Reserved.
 * @license http://www.apache.org/licenses/LICENSE-2.0
 * @package	FitPHP
 * @subpackage library
 * 
 * @author Hongbin Hsu <hongbin.hsu@gmail.com> Initial.
 * @version $Id: helper/array.php 1.0 2010-09-18 16:52 hongbin.hsu $
 */

// ------------------------------------------------------------------------

/**
 * 元素
 *
 * @access	public
 * @param	string $item	键名
 * @param	array  $array	数组
 * @param	mixed  $default	该键不存在或键值为空时返回值[默认为false]
 * @return	mixed
 */	
if (!function_exists('element'))
{
	function element($item, $array, $default = false)
	{
		if (!isset($array[$item]) OR $array[$item] == '')
		{
			return $default;
		}

		return $array[$item];
	}	
}

// ------------------------------------------------------------------------

/**
 *	随机数组	[参考：array_unshift]
 *
 * @access	public
 * @param	array $array
 * @return	mixed
 */	
if (!function_exists('random_element'))
{
	function random_element($array)
	{
		if (!is_array($array))
		{
			return $array;
		}
		return $array[array_rand($array)];
	}
}